package org.paradigmshift.cumulusfracto.core;

import java.io.IOException;
import java.net.SocketException;
import org.alfresco.jlan.server.config.InvalidConfigurationException;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.paradigmshift.cumulusfracto.filesystem.CumulusFractoCifsServer;

public class CumulusFracto {
	
	private static final Logger log = Logger.getLogger( CumulusFracto.class );
	
	public static final String APP_NAME = "Cumulus Fracto";
	private static final String LOG_CONFIG = "log4j-config.xml";
	
	private CumulusFractoCifsServer cifsServer = new CumulusFractoCifsServer();
	
	public CumulusFracto() {
		
	}
	
	public void startCifsServer() {
		
		try {
			
			if ( log.isDebugEnabled() ) log.debug( "Starting CIFS server..." );
			cifsServer.start();
			if ( log.isInfoEnabled() ) log.info( "CIFS server started." );
			
			try {
				cifsServer.addDisk( "Test", "" );
			}
			catch ( InvalidConfigurationException e ) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		catch ( SocketException se ) {
			
			log.error( "Failed to start CIFS server.", se );
		}
		catch ( IOException ioe ) {
			
			log.error( "Failed to start CIFS server.", ioe );
		}
	}
	
	public void stopCifsServer() {
		
		if ( log.isDebugEnabled() ) log.debug( "Stopping CIFS server..." );
		cifsServer.stop();
		if ( log.isInfoEnabled() ) log.info( "CIFS server stopped." );
	}
	
	public static void main( String args[] ) {

		// Setup Log4j
		DOMConfigurator.configure( LOG_CONFIG );
		
		CumulusFracto cumulusFracto = new CumulusFracto();
		cumulusFracto.startCifsServer();
	}
}
